<template>
	<view class="list_box">
		<view class="left">
			<scroll-view scroll-y="true" :style="{ 'height':scrollHeight }">
				<view class="item" v-for="(item,index) in leftArray" :key="index" :class="{ 'active':index==leftIndex }"
				 :data-index="index" @tap="leftTap">
					<text :style="{'font-size':'26rpx'}">{{item.name}}</text>
				</view>
			</scroll-view>
		</view>
		<view class="main">
			<swiper @change="swiperChange" class="swiper" :style="{ 'height':scrollHeight }" :current="leftIndex" vertical="true"
			 duration="300">
				<swiper-item v-for="(item,index) in leftArray" :key="index">
					<scroll-view scroll-y="true" :style="{ 'height':scrollHeight }">
						<!-- <view v-for="(mainArrayItem,index1) in leftArray[index].mainArray" :key="index1" :class="{ 'active':index1==2 ,'item':true}">
							<text :style="{'font-size':'22rpx'}">
								{{mainArrayItem.name}}
							</text>
						</view> -->
						<view v-for="i in 3" :key="i" style="margin: 30upx;border-bottom: 1upx solid #EEEEEE;">
							<image style="width: 100%;height: 350upx;" src="../../static/5c331ec8ad0767c2f78171ffa13c2ee0.jpg"></image>
							<view style="display: flex;align-items: center;">
								<text style="font-weight: bold;margin-right: 20upx;">商品标题商品标题商品标题商品标题商品标题</text>
								<view style="padding-left: 10upx;border-left: 1upx solid #EEEEEE;">
									<image style="width: 40upx;height: 40upx;" src="../../static/tabbar/mine02.png"></image>
								</view>
							</view>
							<view style="font-size: 20upx;">
								<text style="background-color: #FFF6F4;color: #FF795D;">预计2020-08-09配送</text>
								<text style="float: right;">已抢<text style="color: #FF387B;">43</text>件</text>
							</view>
							<view style="display: flex;flex-direction: row;justify-content: space-between;">
								<view>
									<text style="font-size: 45upx;color: #FB206A;font-weight: bold;">￥32.9</text>
									<text style="font-size: 25upx;color: #BBBBBB;">￥49.9</text>
								</view>
								<view style="font-size: 45upx;">
									- 0 +
								</view>
							</view>
						</view>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'bookCategory',
		data() {
			return {
				scrollHeight: 500,
				leftArray: [{
						name: '全部',
						mainArray: [{
								id: 123,
								name: "设计心理学"
							},
							{
								id: 123,
								name: "色彩心理学"
							},
							{
								id: 123,
								name: "环境心理学"
							},
							{
								id: 123,
								name: "研究生/本科/专科教材"
							}
						]
					},
					{
						name: '政治',
						mainArray: [{
								id: 123,
								name: "设计心理学1"
							},
							{
								id: 123,
								name: "设计心理学"
							}
						]
					},
					{
						name: '文学鉴赏',
						mainArray: [{
								id: 123,
								name: "设计心理学2"
							},
							{
								id: 123,
								name: "设计心理学"
							}
						]
					},
				],

				leftIndex: 0
			}
		},
		created() {
			/* 设置当前滚动容器的高，若非窗口的高度，请自行修改 */
			uni.getSystemInfo({
				success: (res) => {
					this.scrollHeight = `${res.windowHeight}px`;
					// uni.showToast({
					// 	title: ''+this.scrollHeight,
					// 	icon: 'none'
					// });
				}
			});
		},
		methods: {
			/* 左侧导航点击 */
			leftTap(e) {
				let index = e.currentTarget.dataset.index;
				this.leftIndex = Number(index);
			},
			swiperChange(e) {

				this.leftIndex = e.detail.current

			}
		}
	}
</script>

<style lang="scss">
	.list_box {
		display: flex;
		flex-direction: row;
		flex-wrap: nowrap;
		justify-content: flex-start;
		align-items: flex-start;
		align-content: flex-start;
		font-size: 26rpx;

		.left {
			width: 180rpx;
			background-color: #F6FAFB;
			box-sizing: border-box;
			font-size: 26rpx;
			text-align: center;
			color: #ABB3B4;

			.item {
				position: relative;
				height: 80rpx;

				text {
					display: block;
					width: 120rpx;
					text-align: center;
					position: relative;
					margin: 0 auto;
					top: 50%;
					transform: translateY(-50%);
				}

				&.active,
				&:active {
					color: #FF387B;
					background-color: #fff;
					font-weight: bold;

					&::after {
						content: '';
						display: block;
						height: 76rpx;
						width: 8rpx;
						background: linear-gradient(90deg, rgba(255, 56, 123, 1) 0%, rgba(255, 56, 123, 1) 100%);
						border-radius: 6rpx;
						position: absolute;
						top: 3rpx;
						left: 0;
						transform: scaleY(0.5);
					}
				}
			}
		}

		.main {
			background-color: #fff;
			padding-left: 5rpx;
			width: 0;
			flex-grow: 1;
			box-sizing: border-box;

			.swiper {
				// height: 500px;
			}

			.title {
				line-height: 64rpx;
				font-size: 24rpx;
				font-weight: bold;
				color: #666;
				background-color: #fff;
				position: sticky;
				top: 0;
				z-index: 999;
			}

			.item {
				width: 156rpx;
				height: 100rpx;
				background: rgba(255, 255, 255, 1);
				border-radius: 8rpx;
				border: 1px solid rgba(171, 179, 180, 1);
				float: left;
				margin-right: 22rpx;
				margin-bottom: 22rpx;
				color: #2C343F;

				text {
					display: block;
					width: 120rpx;
					text-align: center;
					position: relative;
					margin: 0 auto;
					top: 50%;
					transform: translateY(-50%);
				}

				&.active,
				&:active {
					color: #FF387B;
					border-color: #FF387B;
				}
			}

			.goods {
				display: flex;
				flex-direction: row;
				flex-wrap: nowrap;
				justify-content: flex-start;
				align-items: center;
				align-content: center;
				margin-bottom: 10rpx;

				&>image {
					width: 120rpx;
					height: 120rpx;
					margin-right: 16rpx;
				}

				.describe {
					font-size: 24rpx;
					color: #999;
				}

				.money {
					font-size: 24rpx;
					color: #efba21;
				}
			}
		}
	}
</style>
